package com.shudes.container;

import com.shudes.pt.container.*;

public class ContainerMapFilter<P,C> {
	
	protected Filter<C> childFilter; 
	protected Filter<P> parentFilter; 
	
	public ContainerMapFilter(Filter<C> child) {
		this(child,null); 
	}
	
	public ContainerMapFilter(Filter<C> child, Filter<P> parent) {
		this.childFilter=child; 
		this.parentFilter=parent; 
	}
	
	public ContainerMap<P,C> filter(ContainerMap<P,C> map) {
		ContainerMap<P,C> m;
		Container<P,C> nc;
		ContainerFilter<P,C> cf;
		
		cf = new ContainerFilter<P,C>(childFilter); 		
		m = map.newContainerMap();
		
		for(Container<P,C> c : map) {
			if(parentFilter!=null && parentFilter.include(c.getParent())) {
				nc = cf.filter(c);
				m.addContainer(nc); 
			}
			
		}
		return m;
	}	

}
